import request from "@/utils/request";
import type{ MenuQuery, MenuVO, MenuForm, RouteVO } from "./model";
import type { OptionType } from "element-plus/es/components/select-v2/src/select.types.mjs";

 /**
   * 获取路由列表
   */
export function getRoutes(){
  return request<any,RouteVO[]>({
    url:'/api/v1/menus/routes',
    method:'get',
    headers:{
      "Content-Type":"application/x-www-form-urlencoded"
    }
  })
}

/**
   * 获取菜单树形列表
   *
   * @param queryParams
   */
export function getList(queryParams:MenuQuery){
  return request<any,MenuVO[]>({
    url:"/api/v1/menus",
    method:'get',
    params:queryParams,
    headers:{
      "Content-Type":"application/x-www-form-urlencoded"
    }
  })
}


  /**
   * 获取菜单下拉数据源
   */
export function getOptions(){
  return request<any,OptionType[]>({
    url:'/api/v1/menus/options',
    method:'get',
    headers:{
      "Content-Type":"application/x-www-form-urlencoded"
    }
  })
}

/**
   * 获取菜单表单数据
   *
   * @param id
   */
export function getFormData(id:number){
  return request<any,MenuForm>({
    url:'/api/v1/menus/' + id + '/form',
    method:'get',
    headers:{
      "Content-Type":"application/x-www-form-urlencoded"
    }
  })
}

/**
   * 添加菜单
   *
   * @param data
   */
export function add(data:MenuForm){
  return request({
    url:'/api/v1/menus',
    method:"post",
    data:data,
    headers:{
      "Content-Type":"application/json"
    }
  })
}

/**
   * 修改菜单
   *
   * @param id
   * @param data
   */
export function update(id:string,data:MenuForm){
  return request({
    url:'/api/v1/menus/' + id,
    method:"put",
    data:data,
    headers:{
      "Content-Type":"application/json"
    }
  })
}

 /**
   * 删除菜单
   *
   * @param id 菜单ID
   */
export function deleteById(id:number){
  return request({
    url:'/api/v1/menus/' + id,
    method:"delete",
    headers:{
      "Content-Type":"application/x-www-form-urlencoded"
    }
  })
}